import Api from '../../http/Api';
import { tokenInterceptor } from '../Interceptors';
class BaseService extends Api {
	constructor() {
		super(...arguments);
		this.initTokenInstance = key => {
			return this.initSingle(
				key,
				{
					baseURL: `/api/${key}`
				},
				tokenInterceptor
			);
		};
		this.selectOneById = id =>
			this.request({
				method: this.method.GET,
				url: `/id/${id}`
			});
		this.selectOne = record =>
			this.request({
				method: this.method.POST,
				url: '/search',
				data: record
			});
		this.selectByIds = list =>
			this.request({
				method: this.method.POST,
				url: '/list/id',
				data: list
			});
		this.select = condition =>
			this.request({
				method: this.method.POST,
				url: '/list/search',
				data: condition
			});
		this.selectLike = condition =>
			this.request({
				method: this.method.POST,
				url: '/list/like',
				data: condition
			});
		this.selectAll = condition =>
			this.request({
				method: this.method.GET,
				url: '/list',
				data: condition
			});
		this.selectCount = record =>
			this.request({
				method: this.method.POST,
				url: '/count',
				data: record
			});
		this.insert = record =>
			this.request({
				method: this.method.POST,
				data: record
			});
		this.insertList = records =>
			this.request({
				method: this.method.POST,
				url: '/list',
				data: records
			});
		this.save = record =>
			this.request({
				method: this.method.PUT,
				data: record
			});
		this.saveList = records =>
			this.request({
				method: this.method.PUT,
				url: '/list',
				data: records
			});
		this.update = record =>
			this.request({
				method: this.method.PATCH,
				data: record
			});
		this.updateList = records =>
			this.request({
				method: this.method.PATCH,
				url: '/list',
				data: records
			});
		this.deleteById = id =>
			this.request({
				method: this.method.DELETE,
				url: `/id/${id}`
			});
		this.deleteByIds = list =>
			this.request({
				method: this.method.DELETE,
				url: '/list/id',
				data: list
			});
	}
}
export class DataService extends BaseService {
	constructor() {
		super();
		this.create();
	}
}
